home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_perl.idb / usr / freeware / lib / perl5 / 5.00502 / Getopt / Long.pm.z / Long.pm
Encoding:
Perl POD Document  |  1998-10-28  |  39.4 KB  |  1,382 lines

  1. # GetOpt::Long.pm -- Universal options parsing
  2.  
  3. package Getopt::Long;
  4.  
  5. # RCS Status      : $Id: GetoptLong.pl,v 2.18 1998-06-14 15:02:19+02 jv Exp $
  6. # Author          : Johan Vromans
  7. # Created On      : Tue Sep 11 15:00:12 1990
  8. # Last Modified By: Johan Vromans
  9. # Last Modified On: Sun Jun 14 13:17:22 1998
  10. # Update Count    : 705
  11. # Status          : Released
  12.  
  13. ################ Copyright ################
  14.  
  15. # This program is Copyright 1990,1998 by Johan Vromans.
  16. # This program is free software; you can redistribute it and/or
  17. # modify it under the terms of the GNU General Public License
  18. # as published by the Free Software Foundation; either version 2
  19. # of the License, or (at your option) any later version.
  20. # This program is distributed in the hope that it will be useful,
  21. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  22. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  23. # GNU General Public License for more details.
  24. # If you do not have a copy of the GNU General Public License write to
  25. # the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, 
  26. # MA 02139, USA.
  27.  
  28. ################ Module Preamble ################
  29.  
  30. use strict;
  31.  
  32. BEGIN {
  33.     require 5.004;
  34.     use Exporter ();
  35.     use vars     qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
  36.     $VERSION     = "2.17";
  37.  
  38.     @ISA         = qw(Exporter);
  39.     @EXPORT      = qw(&GetOptions $REQUIRE_ORDER $PERMUTE $RETURN_IN_ORDER);
  40.     %EXPORT_TAGS = qw();
  41.     @EXPORT_OK   = qw();
  42.     use AutoLoader qw(AUTOLOAD);
  43. }
  44.  
  45. # User visible variables.
  46. use vars @EXPORT, @EXPORT_OK;
  47. use vars qw($error $debug $major_version $minor_version);
  48. # Deprecated visible variables.
  49. use vars qw($autoabbrev $getopt_compat $ignorecase $bundling $order
  50.         $passthrough);
  51. # Official invisible variables.
  52. use vars qw($genprefix);
  53.  
  54. # Public subroutines. 
  55. sub Configure (@);
  56. sub config (@);            # deprecated name
  57. sub GetOptions;
  58.  
  59. # Private subroutines. 
  60. sub ConfigDefaults ();
  61. sub FindOption ($$$$$$$);
  62. sub Croak (@);            # demand loading the real Croak
  63.  
  64. ################ Local Variables ################
  65.  
  66. ################ Resident subroutines ################
  67.  
  68. sub ConfigDefaults () {
  69.     # Handle POSIX compliancy.
  70.     if ( defined $ENV{"POSIXLY_CORRECT"} ) {
  71.     $genprefix = "(--|-)";
  72.     $autoabbrev = 0;        # no automatic abbrev of options
  73.     $bundling = 0;            # no bundling of single letter switches
  74.     $getopt_compat = 0;        # disallow '+' to start options
  75.     $order = $REQUIRE_ORDER;
  76.     }
  77.     else {
  78.     $genprefix = "(--|-|\\+)";
  79.     $autoabbrev = 1;        # automatic abbrev of options
  80.     $bundling = 0;            # bundling off by default
  81.     $getopt_compat = 1;        # allow '+' to start options
  82.     $order = $PERMUTE;
  83.     }
  84.     # Other configurable settings.
  85.     $debug = 0;            # for debugging
  86.     $error = 0;            # error tally
  87.     $ignorecase = 1;        # ignore case when matching options
  88.     $passthrough = 0;        # leave unrecognized options alone
  89. }
  90.  
  91. ################ Initialization ################
  92.  
  93. # Values for $order. See GNU getopt.c for details.
  94. ($REQUIRE_ORDER, $PERMUTE, $RETURN_IN_ORDER) = (0..2);
  95. # Version major/minor numbers.
  96. ($major_version, $minor_version) = $VERSION =~ /^(\d+)\.(\d+)/;
  97.  
  98. # Set defaults.
  99. ConfigDefaults ();
  100.  
  101. ################ Package return ################
  102.  
  103. 1;
  104.  
  105. __END__
  106.  
  107. ################ AutoLoading subroutines ################
  108.  
  109. # RCS Status      : $Id: GetoptLongAl.pl,v 2.20 1998-06-14 15:02:19+02 jv Exp $
  110. # Author          : Johan Vromans
  111. # Created On      : Fri Mar 27 11:50:30 1998
  112. # Last Modified By: Johan Vromans
  113. # Last Modified On: Sun Jun 14 13:54:35 1998
  114. # Update Count    : 24
  115. # Status          : Released
  116.  
  117. sub GetOptions {
  118.  
  119.     my @optionlist = @_;    # local copy of the option descriptions
  120.     my $argend = '--';        # option list terminator
  121.     my %opctl = ();        # table of arg.specs (long and abbrevs)
  122.     my %bopctl = ();        # table of arg.specs (bundles)
  123.     my $pkg = (caller)[0];    # current context
  124.                 # Needed if linkage is omitted.
  125.     my %aliases= ();        # alias table
  126.     my @ret = ();        # accum for non-options
  127.     my %linkage;        # linkage
  128.     my $userlinkage;        # user supplied HASH
  129.     my $opt;            # current option
  130.     my $genprefix = $genprefix;    # so we can call the same module many times
  131.     my @opctl;            # the possible long option names
  132.  
  133.     $error = '';
  134.  
  135.     print STDERR ("GetOpt::Long $Getopt::Long::VERSION ",
  136.           "called from package \"$pkg\".",
  137.           "\n  ",
  138.           'GetOptionsAl $Revision: 2.20 $ ',
  139.           "\n  ",
  140.           "ARGV: (@ARGV)",
  141.           "\n  ",
  142.           "autoabbrev=$autoabbrev,".
  143.           "bundling=$bundling,",
  144.           "getopt_compat=$getopt_compat,",
  145.           "order=$order,",
  146.           "\n  ",
  147.           "ignorecase=$ignorecase,",
  148.           "passthrough=$passthrough,",
  149.           "genprefix=\"$genprefix\".",
  150.           "\n")
  151.     if $debug;
  152.  
  153.     # Check for ref HASH as first argument. 
  154.     # First argument may be an object. It's OK to use this as long
  155.     # as it is really a hash underneath. 
  156.     $userlinkage = undef;
  157.     if ( ref($optionlist[0]) and
  158.      "$optionlist[0]" =~ /^(?:.*\=)?HASH\([^\(]*\)$/ ) {
  159.     $userlinkage = shift (@optionlist);
  160.     print STDERR ("=> user linkage: $userlinkage\n") if $debug;
  161.     }
  162.  
  163.     # See if the first element of the optionlist contains option
  164.     # starter characters.
  165.     if ( $optionlist[0] =~ /^\W+$/ ) {
  166.     $genprefix = shift (@optionlist);
  167.     # Turn into regexp. Needs to be parenthesized!
  168.     $genprefix =~ s/(\W)/\\$1/g;
  169.     $genprefix = "([" . $genprefix . "])";
  170.     }
  171.  
  172.     # Verify correctness of optionlist.
  173.     %opctl = ();
  174.     %bopctl = ();
  175.     while ( @optionlist > 0 ) {
  176.     my $opt = shift (@optionlist);
  177.  
  178.     # Strip leading prefix so people can specify "--foo=i" if they like.
  179.     $opt = $+ if $opt =~ /^$genprefix+(.*)$/s;
  180.  
  181.     if ( $opt eq '<>' ) {
  182.         if ( (defined $userlinkage)
  183.         && !(@optionlist > 0 && ref($optionlist[0]))
  184.         && (exists $userlinkage->{$opt})
  185.         && ref($userlinkage->{$opt}) ) {
  186.         unshift (@optionlist, $userlinkage->{$opt});
  187.         }
  188.         unless ( @optionlist > 0 
  189.             && ref($optionlist[0]) && ref($optionlist[0]) eq 'CODE' ) {
  190.         $error .= "Option spec <> requires a reference to a subroutine\n";
  191.         next;
  192.         }
  193.         $linkage{'<>'} = shift (@optionlist);
  194.         next;
  195.     }
  196.  
  197.     # Match option spec. Allow '?' as an alias.
  198.     if ( $opt !~ /^((\w+[-\w]*)(\|(\?|\w[-\w]*)?)*)?([!~+]|[=:][infse][@%]?)?$/ ) {
  199.         $error .= "Error in option spec: \"$opt\"\n";
  200.         next;
  201.     }
  202.     my ($o, $c, $a) = ($1, $5);
  203.     $c = '' unless defined $c;
  204.  
  205.     if ( ! defined $o ) {
  206.         # empty -> '-' option
  207.         $opctl{$o = ''} = $c;
  208.     }
  209.     else {
  210.         # Handle alias names
  211.         my @o =  split (/\|/, $o);
  212.         my $linko = $o = $o[0];
  213.         # Force an alias if the option name is not locase.
  214.         $a = $o unless $o eq lc($o);
  215.         $o = lc ($o)
  216.         if $ignorecase > 1 
  217.             || ($ignorecase
  218.             && ($bundling ? length($o) > 1  : 1));
  219.  
  220.         foreach ( @o ) {
  221.         if ( $bundling && length($_) == 1 ) {
  222.             $_ = lc ($_) if $ignorecase > 1;
  223.             if ( $c eq '!' ) {
  224.             $opctl{"no$_"} = $c;
  225.             warn ("Ignoring '!' modifier for short option $_\n");
  226.             $c = '';
  227.             }
  228.             $opctl{$_} = $bopctl{$_} = $c;
  229.         }
  230.         else {
  231.             $_ = lc ($_) if $ignorecase;
  232.             if ( $c eq '!' ) {
  233.             $opctl{"no$_"} = $c;
  234.             $c = '';
  235.             }
  236.             $opctl{$_} = $c;
  237.         }
  238.         if ( defined $a ) {
  239.             # Note alias.
  240.             $aliases{$_} = $a;
  241.         }
  242.         else {
  243.             # Set primary name.
  244.             $a = $_;
  245.         }
  246.         }
  247.         $o = $linko;
  248.     }
  249.  
  250.     # If no linkage is supplied in the @optionlist, copy it from
  251.     # the userlinkage if available.
  252.     if ( defined $userlinkage ) {
  253.         unless ( @optionlist > 0 && ref($optionlist[0]) ) {
  254.         if ( exists $userlinkage->{$o} && ref($userlinkage->{$o}) ) {
  255.             print STDERR ("=> found userlinkage for \"$o\": ",
  256.                   "$userlinkage->{$o}\n")
  257.             if $debug;
  258.             unshift (@optionlist, $userlinkage->{$o});
  259.         }
  260.         else {
  261.             # Do nothing. Being undefined will be handled later.
  262.             next;
  263.         }
  264.         }
  265.     }
  266.  
  267.     # Copy the linkage. If omitted, link to global variable.
  268.     if ( @optionlist > 0 && ref($optionlist[0]) ) {
  269.         print STDERR ("=> link \"$o\" to $optionlist[0]\n")
  270.         if $debug;
  271.         if ( ref($optionlist[0]) =~ /^(SCALAR|CODE)$/ ) {
  272.         $linkage{$o} = shift (@optionlist);
  273.         }
  274.         elsif ( ref($optionlist[0]) =~ /^(ARRAY)$/ ) {
  275.         $linkage{$o} = shift (@optionlist);
  276.         $opctl{$o} .= '@'
  277.           if $opctl{$o} ne '' and $opctl{$o} !~ /\@$/;
  278.         $bopctl{$o} .= '@'
  279.           if $bundling and defined $bopctl{$o} and 
  280.             $bopctl{$o} ne '' and $bopctl{$o} !~ /\@$/;
  281.         }
  282.         elsif ( ref($optionlist[0]) =~ /^(HASH)$/ ) {
  283.         $linkage{$o} = shift (@optionlist);
  284.         $opctl{$o} .= '%'
  285.           if $opctl{$o} ne '' and $opctl{$o} !~ /\%$/;
  286.         $bopctl{$o} .= '%'
  287.           if $bundling and defined $bopctl{$o} and 
  288.             $bopctl{$o} ne '' and $bopctl{$o} !~ /\%$/;
  289.         }
  290.         else {
  291.         $error .= "Invalid option linkage for \"$opt\"\n";
  292.         }
  293.     }
  294.     else {
  295.         # Link to global $opt_XXX variable.
  296.         # Make sure a valid perl identifier results.
  297.         my $ov = $o;
  298.         $ov =~ s/\W/_/g;
  299.         if ( $c =~ /@/ ) {
  300.         print STDERR ("=> link \"$o\" to \@$pkg","::opt_$ov\n")
  301.             if $debug;
  302.         eval ("\$linkage{\$o} = \\\@".$pkg."::opt_$ov;");
  303.         }
  304.         elsif ( $c =~ /%/ ) {
  305.         print STDERR ("=> link \"$o\" to \%$pkg","::opt_$ov\n")
  306.             if $debug;
  307.         eval ("\$linkage{\$o} = \\\%".$pkg."::opt_$ov;");
  308.         }
  309.         else {
  310.         print STDERR ("=> link \"$o\" to \$$pkg","::opt_$ov\n")
  311.             if $debug;
  312.         eval ("\$linkage{\$o} = \\\$".$pkg."::opt_$ov;");
  313.         }
  314.     }
  315.     }
  316.  
  317.     # Bail out if errors found.
  318.     die ($error) if $error;
  319.     $error = 0;
  320.  
  321.     # Sort the possible long option names.
  322.     @opctl = sort(keys (%opctl)) if $autoabbrev;
  323.  
  324.     # Show the options tables if debugging.
  325.     if ( $debug ) {
  326.     my ($arrow, $k, $v);
  327.     $arrow = "=> ";
  328.     while ( ($k,$v) = each(%opctl) ) {
  329.         print STDERR ($arrow, "\$opctl{\"$k\"} = \"$v\"\n");
  330.         $arrow = "   ";
  331.     }
  332.     $arrow = "=> ";
  333.     while ( ($k,$v) = each(%bopctl) ) {
  334.         print STDERR ($arrow, "\$bopctl{\"$k\"} = \"$v\"\n");
  335.         $arrow = "   ";
  336.     }
  337.     }
  338.  
  339.     # Process argument list
  340.     while ( @ARGV > 0 ) {
  341.  
  342.     #### Get next argument ####
  343.  
  344.     $opt = shift (@ARGV);
  345.     print STDERR ("=> option \"", $opt, "\"\n") if $debug;
  346.  
  347.     #### Determine what we have ####
  348.  
  349.     # Double dash is option list terminator.
  350.     if ( $opt eq $argend ) {
  351.         # Finish. Push back accumulated arguments and return.
  352.         unshift (@ARGV, @ret) 
  353.         if $order == $PERMUTE;
  354.         return ($error == 0);
  355.     }
  356.  
  357.     my $tryopt = $opt;
  358.     my $found;        # success status
  359.     my $dsttype;        # destination type ('@' or '%')
  360.     my $incr;        # destination increment 
  361.     my $key;        # key (if hash type)
  362.     my $arg;        # option argument
  363.  
  364.     ($found, $opt, $arg, $dsttype, $incr, $key) = 
  365.       FindOption ($genprefix, $argend, $opt, 
  366.               \%opctl, \%bopctl, \@opctl, \%aliases);
  367.  
  368.     if ( $found ) {
  369.         
  370.         # FindOption undefines $opt in case of errors.
  371.         next unless defined $opt;
  372.  
  373.         if ( defined $arg ) {
  374.         $opt = $aliases{$opt} if defined $aliases{$opt};
  375.  
  376.         if ( defined $linkage{$opt} ) {
  377.             print STDERR ("=> ref(\$L{$opt}) -> ",
  378.                   ref($linkage{$opt}), "\n") if $debug;
  379.  
  380.             if ( ref($linkage{$opt}) eq 'SCALAR' ) {
  381.             if ( $incr ) {
  382.                 print STDERR ("=> \$\$L{$opt} += \"$arg\"\n")
  383.                   if $debug;
  384.                 if ( defined ${$linkage{$opt}} ) {
  385.                     ${$linkage{$opt}} += $arg;
  386.                 }
  387.                     else {
  388.                     ${$linkage{$opt}} = $arg;
  389.                 }
  390.             }
  391.             else {
  392.                 print STDERR ("=> \$\$L{$opt} = \"$arg\"\n")
  393.                   if $debug;
  394.                 ${$linkage{$opt}} = $arg;
  395.                 }
  396.             }
  397.             elsif ( ref($linkage{$opt}) eq 'ARRAY' ) {
  398.             print STDERR ("=> push(\@{\$L{$opt}, \"$arg\")\n")
  399.                 if $debug;
  400.             push (@{$linkage{$opt}}, $arg);
  401.             }
  402.             elsif ( ref($linkage{$opt}) eq 'HASH' ) {
  403.             print STDERR ("=> \$\$L{$opt}->{$key} = \"$arg\"\n")
  404.                 if $debug;
  405.             $linkage{$opt}->{$key} = $arg;
  406.             }
  407.             elsif ( ref($linkage{$opt}) eq 'CODE' ) {
  408.             print STDERR ("=> &L{$opt}(\"$opt\", \"$arg\")\n")
  409.                 if $debug;
  410.             &{$linkage{$opt}}($opt, $arg);
  411.             }
  412.             else {
  413.             print STDERR ("Invalid REF type \"", ref($linkage{$opt}),
  414.                       "\" in linkage\n");
  415.             Croak ("Getopt::Long -- internal error!\n");
  416.             }
  417.         }
  418.         # No entry in linkage means entry in userlinkage.
  419.         elsif ( $dsttype eq '@' ) {
  420.             if ( defined $userlinkage->{$opt} ) {
  421.             print STDERR ("=> push(\@{\$L{$opt}}, \"$arg\")\n")
  422.                 if $debug;
  423.             push (@{$userlinkage->{$opt}}, $arg);
  424.             }
  425.             else {
  426.             print STDERR ("=>\$L{$opt} = [\"$arg\"]\n")
  427.                 if $debug;
  428.             $userlinkage->{$opt} = [$arg];
  429.             }
  430.         }
  431.         elsif ( $dsttype eq '%' ) {
  432.             if ( defined $userlinkage->{$opt} ) {
  433.             print STDERR ("=> \$L{$opt}->{$key} = \"$arg\"\n")
  434.                 if $debug;
  435.             $userlinkage->{$opt}->{$key} = $arg;
  436.             }
  437.             else {
  438.             print STDERR ("=>\$L{$opt} = {$key => \"$arg\"}\n")
  439.                 if $debug;
  440.             $userlinkage->{$opt} = {$key => $arg};
  441.             }
  442.         }
  443.         else {
  444.             if ( $incr ) {
  445.             print STDERR ("=> \$L{$opt} += \"$arg\"\n")
  446.               if $debug;
  447.             if ( defined $userlinkage->{$opt} ) {
  448.                 $userlinkage->{$opt} += $arg;
  449.             }
  450.             else {
  451.                 $userlinkage->{$opt} = $arg;
  452.             }
  453.             }
  454.             else {
  455.             print STDERR ("=>\$L{$opt} = \"$arg\"\n") if $debug;
  456.             $userlinkage->{$opt} = $arg;
  457.             }
  458.         }
  459.         }
  460.     }
  461.  
  462.     # Not an option. Save it if we $PERMUTE and don't have a <>.
  463.     elsif ( $order == $PERMUTE ) {
  464.         # Try non-options call-back.
  465.         my $cb;
  466.         if ( (defined ($cb = $linkage{'<>'})) ) {
  467.         &$cb ($tryopt);
  468.         }
  469.         else {
  470.         print STDERR ("=> saving \"$tryopt\" ",
  471.                   "(not an option, may permute)\n") if $debug;
  472.         push (@ret, $tryopt);
  473.         }
  474.         next;
  475.     }
  476.  
  477.     # ...otherwise, terminate.
  478.     else {
  479.         # Push this one back and exit.
  480.         unshift (@ARGV, $tryopt);
  481.         return ($error == 0);
  482.     }
  483.  
  484.     }
  485.  
  486.     # Finish.
  487.     if ( $order == $PERMUTE ) {
  488.     #  Push back accumulated arguments
  489.     print STDERR ("=> restoring \"", join('" "', @ret), "\"\n")
  490.         if $debug && @ret > 0;
  491.     unshift (@ARGV, @ret) if @ret > 0;
  492.     }
  493.  
  494.     return ($error == 0);
  495. }
  496.  
  497. # Option lookup.
  498. sub FindOption ($$$$$$$) {
  499.  
  500.     # returns (1, $opt, $arg, $dsttype, $incr, $key) if okay,
  501.     # returns (0) otherwise.
  502.  
  503.     my ($prefix, $argend, $opt, $opctl, $bopctl, $names, $aliases) = @_;
  504.     my $key;            # hash key for a hash option
  505.     my $arg;
  506.  
  507.     print STDERR ("=> find \"$opt\", prefix=\"$prefix\"\n") if $debug;
  508.  
  509.     return (0) unless $opt =~ /^$prefix(.*)$/s;
  510.  
  511.     $opt = $+;
  512.     my ($starter) = $1;
  513.  
  514.     print STDERR ("=> split \"$starter\"+\"$opt\"\n") if $debug;
  515.  
  516.     my $optarg = undef;    # value supplied with --opt=value
  517.     my $rest = undef;    # remainder from unbundling
  518.  
  519.     # If it is a long option, it may include the value.
  520.     if (($starter eq "--" || ($getopt_compat && !$bundling))
  521.     && $opt =~ /^([^=]+)=(.*)$/s ) {
  522.     $opt = $1;
  523.     $optarg = $2;
  524.     print STDERR ("=> option \"", $opt, 
  525.               "\", optarg = \"$optarg\"\n") if $debug;
  526.     }
  527.  
  528.     #### Look it up ###
  529.  
  530.     my $tryopt = $opt;        # option to try
  531.     my $optbl = $opctl;        # table to look it up (long names)
  532.     my $type;
  533.     my $dsttype = '';
  534.     my $incr = 0;
  535.  
  536.     if ( $bundling && $starter eq '-' ) {
  537.     # Unbundle single letter option.
  538.     $rest = substr ($tryopt, 1);
  539.     $tryopt = substr ($tryopt, 0, 1);
  540.     $tryopt = lc ($tryopt) if $ignorecase > 1;
  541.     print STDERR ("=> $starter$tryopt unbundled from ",
  542.               "$starter$tryopt$rest\n") if $debug;
  543.     $rest = undef unless $rest ne '';
  544.     $optbl = $bopctl;    # look it up in the short names table
  545.  
  546.     # If bundling == 2, long options can override bundles.
  547.     if ( $bundling == 2 and
  548.          defined ($type = $opctl->{$tryopt.$rest}) ) {
  549.         print STDERR ("=> $starter$tryopt rebundled to ",
  550.               "$starter$tryopt$rest\n") if $debug;
  551.         $tryopt .= $rest;
  552.         undef $rest;
  553.     }
  554.     } 
  555.  
  556.     # Try auto-abbreviation.
  557.     elsif ( $autoabbrev ) {
  558.     # Downcase if allowed.
  559.     $tryopt = $opt = lc ($opt) if $ignorecase;
  560.     # Turn option name into pattern.
  561.     my $pat = quotemeta ($opt);
  562.     # Look up in option names.
  563.     my @hits = grep (/^$pat/, @{$names});
  564.     print STDERR ("=> ", scalar(@hits), " hits (@hits) with \"$pat\" ",
  565.               "out of ", scalar(@{$names}), "\n") if $debug;
  566.  
  567.     # Check for ambiguous results.
  568.     unless ( (@hits <= 1) || (grep ($_ eq $opt, @hits) == 1) ) {
  569.         # See if all matches are for the same option.
  570.         my %hit;
  571.         foreach ( @hits ) {
  572.         $_ = $aliases->{$_} if defined $aliases->{$_};
  573.         $hit{$_} = 1;
  574.         }
  575.         # Now see if it really is ambiguous.
  576.         unless ( keys(%hit) == 1 ) {
  577.         return (0) if $passthrough;
  578.         warn ("Option ", $opt, " is ambiguous (",
  579.               join(", ", @hits), ")\n");
  580.         $error++;
  581.         undef $opt;
  582.         return (1, $opt,$arg,$dsttype,$incr,$key);
  583.         }
  584.         @hits = keys(%hit);
  585.     }
  586.  
  587.     # Complete the option name, if appropriate.
  588.     if ( @hits == 1 && $hits[0] ne $opt ) {
  589.         $tryopt = $hits[0];
  590.         $tryopt = lc ($tryopt) if $ignorecase;
  591.         print STDERR ("=> option \"$opt\" -> \"$tryopt\"\n")
  592.         if $debug;
  593.     }
  594.     }
  595.  
  596.     # Map to all lowercase if ignoring case.
  597.     elsif ( $ignorecase ) {
  598.     $tryopt = lc ($opt);
  599.     }
  600.  
  601.     # Check validity by fetching the info.
  602.     $type = $optbl->{$tryopt} unless defined $type;
  603.     unless  ( defined $type ) {
  604.     return (0) if $passthrough;
  605.     warn ("Unknown option: ", $opt, "\n");
  606.     $error++;
  607.     return (1, $opt,$arg,$dsttype,$incr,$key);
  608.     }
  609.     # Apparently valid.
  610.     $opt = $tryopt;
  611.     print STDERR ("=> found \"$type\" for ", $opt, "\n") if $debug;
  612.  
  613.     #### Determine argument status ####
  614.  
  615.     # If it is an option w/o argument, we're almost finished with it.
  616.     if ( $type eq '' || $type eq '!' || $type eq '+' ) {
  617.     if ( defined $optarg ) {
  618.         return (0) if $passthrough;
  619.         warn ("Option ", $opt, " does not take an argument\n");
  620.         $error++;
  621.         undef $opt;
  622.     }
  623.     elsif ( $type eq '' || $type eq '+' ) {
  624.         $arg = 1;        # supply explicit value
  625.         $incr = $type eq '+';
  626.     }
  627.     else {
  628.         substr ($opt, 0, 2) = ''; # strip NO prefix
  629.         $arg = 0;        # supply explicit value
  630.     }
  631.     unshift (@ARGV, $starter.$rest) if defined $rest;
  632.     return (1, $opt,$arg,$dsttype,$incr,$key);
  633.     }
  634.  
  635.     # Get mandatory status and type info.
  636.     my $mand;
  637.     ($mand, $type, $dsttype, $key) = $type =~ /^(.)(.)([@%]?)$/;
  638.  
  639.     # Check if there is an option argument available.
  640.     if ( defined $optarg ? ($optarg eq '') 
  641.      : !(defined $rest || @ARGV > 0) ) {
  642.     # Complain if this option needs an argument.
  643.     if ( $mand eq "=" ) {
  644.         return (0) if $passthrough;
  645.         warn ("Option ", $opt, " requires an argument\n");
  646.         $error++;
  647.         undef $opt;
  648.     }
  649.     if ( $mand eq ":" ) {
  650.         $arg = $type eq "s" ? '' : 0;
  651.     }
  652.     return (1, $opt,$arg,$dsttype,$incr,$key);
  653.     }
  654.  
  655.     # Get (possibly optional) argument.
  656.     $arg = (defined $rest ? $rest
  657.         : (defined $optarg ? $optarg : shift (@ARGV)));
  658.  
  659.     # Get key if this is a "name=value" pair for a hash option.
  660.     $key = undef;
  661.     if ($dsttype eq '%' && defined $arg) {
  662.     ($key, $arg) = ($arg =~ /^(.*)=(.*)$/s) ? ($1, $2) : ($arg, 1);
  663.     }
  664.  
  665.     #### Check if the argument is valid for this option ####
  666.  
  667.     if ( $type eq "s" ) {    # string
  668.     # A mandatory string takes anything. 
  669.     return (1, $opt,$arg,$dsttype,$incr,$key) if $mand eq "=";
  670.  
  671.     # An optional string takes almost anything. 
  672.     return (1, $opt,$arg,$dsttype,$incr,$key) 
  673.       if defined $optarg || defined $rest;
  674.     return (1, $opt,$arg,$dsttype,$incr,$key) if $arg eq "-"; # ??
  675.  
  676.     # Check for option or option list terminator.
  677.     if ($arg eq $argend ||
  678.         $arg =~ /^$prefix.+/) {
  679.         # Push back.
  680.         unshift (@ARGV, $arg);
  681.         # Supply empty value.
  682.         $arg = '';
  683.     }
  684.     }
  685.  
  686.     elsif ( $type eq "n" || $type eq "i" ) { # numeric/integer
  687.     if ( $bundling && defined $rest && $rest =~ /^(-?[0-9]+)(.*)$/s ) {
  688.         $arg = $1;
  689.         $rest = $2;
  690.         unshift (@ARGV, $starter.$rest) if defined $rest && $rest ne '';
  691.     }
  692.     elsif ( $arg !~ /^-?[0-9]+$/ ) {
  693.         if ( defined $optarg || $mand eq "=" ) {
  694.         if ( $passthrough ) {
  695.             unshift (@ARGV, defined $rest ? $starter.$rest : $arg)
  696.               unless defined $optarg;
  697.             return (0);
  698.         }
  699.         warn ("Value \"", $arg, "\" invalid for option ",
  700.               $opt, " (number expected)\n");
  701.         $error++;
  702.         undef $opt;
  703.         # Push back.
  704.         unshift (@ARGV, $starter.$rest) if defined $rest;
  705.         }
  706.         else {
  707.         # Push back.
  708.         unshift (@ARGV, defined $rest ? $starter.$rest : $arg);
  709.         # Supply default value.
  710.         $arg = 0;
  711.         }
  712.     }
  713.     }
  714.  
  715.     elsif ( $type eq "f" ) { # real number, int is also ok
  716.     # We require at least one digit before a point or 'e',
  717.     # and at least one digit following the point and 'e'.
  718.     # [-]NN[.NN][eNN]
  719.     if ( $bundling && defined $rest &&
  720.          $rest =~ /^(-?[0-9]+(\.[0-9]+)?([eE]-?[0-9]+)?)(.*)$/s ) {
  721.         $arg = $1;
  722.         $rest = $+;
  723.         unshift (@ARGV, $starter.$rest) if defined $rest && $rest ne '';
  724.     }
  725.     elsif ( $arg !~ /^-?[0-9.]+(\.[0-9]+)?([eE]-?[0-9]+)?$/ ) {
  726.         if ( defined $optarg || $mand eq "=" ) {
  727.         if ( $passthrough ) {
  728.             unshift (@ARGV, defined $rest ? $starter.$rest : $arg)
  729.               unless defined $optarg;
  730.             return (0);
  731.         }
  732.         warn ("Value \"", $arg, "\" invalid for option ",
  733.               $opt, " (real number expected)\n");
  734.         $error++;
  735.         undef $opt;
  736.         # Push back.
  737.         unshift (@ARGV, $starter.$rest) if defined $rest;
  738.         }
  739.         else {
  740.         # Push back.
  741.         unshift (@ARGV, defined $rest ? $starter.$rest : $arg);
  742.         # Supply default value.
  743.         $arg = 0.0;
  744.         }
  745.     }
  746.     }
  747.     else {
  748.     Croak ("GetOpt::Long internal error (Can't happen)\n");
  749.     }
  750.     return (1, $opt, $arg, $dsttype, $incr, $key);
  751. }
  752.  
  753. # Getopt::Long Configuration.
  754. sub Configure (@) {
  755.     my (@options) = @_;
  756.     my $opt;
  757.     foreach $opt ( @options ) {
  758.     my $try = lc ($opt);
  759.     my $action = 1;
  760.     if ( $try =~ /^no_?(.*)$/s ) {
  761.         $action = 0;
  762.         $try = $+;
  763.     }
  764.     if ( $try eq 'default' or $try eq 'defaults' ) {
  765.         ConfigDefaults () if $action;
  766.     }
  767.     elsif ( $try eq 'auto_abbrev' or $try eq 'autoabbrev' ) {
  768.         $autoabbrev = $action;
  769.     }
  770.     elsif ( $try eq 'getopt_compat' ) {
  771.         $getopt_compat = $action;
  772.     }
  773.     elsif ( $try eq 'ignorecase' or $try eq 'ignore_case' ) {
  774.         $ignorecase = $action;
  775.     }
  776.     elsif ( $try eq 'ignore_case_always' ) {
  777.         $ignorecase = $action ? 2 : 0;
  778.     }
  779.     elsif ( $try eq 'bundling' ) {
  780.         $bundling = $action;
  781.     }
  782.     elsif ( $try eq 'bundling_override' ) {
  783.         $bundling = $action ? 2 : 0;
  784.     }
  785.     elsif ( $try eq 'require_order' ) {
  786.         $order = $action ? $REQUIRE_ORDER : $PERMUTE;
  787.     }
  788.     elsif ( $try eq 'permute' ) {
  789.         $order = $action ? $PERMUTE : $REQUIRE_ORDER;
  790.     }
  791.     elsif ( $try eq 'pass_through' or $try eq 'passthrough' ) {
  792.         $passthrough = $action;
  793.     }
  794.     elsif ( $try =~ /^prefix=(.+)$/ ) {
  795.         $genprefix = $1;
  796.         # Turn into regexp. Needs to be parenthesized!
  797.         $genprefix = "(" . quotemeta($genprefix) . ")";
  798.         eval { '' =~ /$genprefix/; };
  799.         Croak ("Getopt::Long: invalid pattern \"$genprefix\"") if $@;
  800.     }
  801.     elsif ( $try =~ /^prefix_pattern=(.+)$/ ) {
  802.         $genprefix = $1;
  803.         # Parenthesize if needed.
  804.         $genprefix = "(" . $genprefix . ")" 
  805.           unless $genprefix =~ /^\(.*\)$/;
  806.         eval { '' =~ /$genprefix/; };
  807.         Croak ("Getopt::Long: invalid pattern \"$genprefix\"") if $@;
  808.     }
  809.     elsif ( $try eq 'debug' ) {
  810.         $debug = $action;
  811.     }
  812.     else {
  813.         Croak ("Getopt::Long: unknown config parameter \"$opt\"")
  814.     }
  815.     }
  816. }
  817.  
  818. # Deprecated name.
  819. sub config (@) {
  820.     Configure (@_);
  821. }
  822.  
  823. # To prevent Carp from being loaded unnecessarily.
  824. sub Croak (@) {
  825.     require 'Carp.pm';
  826.     $Carp::CarpLevel = 1;
  827.     Carp::croak(@_);
  828. };
  829.  
  830. ################ Documentation ################
  831.  
  832. =head1 NAME
  833.  
  834. GetOptions - extended processing of command line options
  835.  
  836. =head1 SYNOPSIS
  837.  
  838.   use Getopt::Long;
  839.   $result = GetOptions (...option-descriptions...);
  840.  
  841. =head1 DESCRIPTION
  842.  
  843. The Getopt::Long module implements an extended getopt function called
  844. GetOptions(). This function adheres to the POSIX syntax for command
  845. line options, with GNU extensions. In general, this means that options
  846. have long names instead of single letters, and are introduced with a
  847. double dash "--". Support for bundling of command line options, as was
  848. the case with the more traditional single-letter approach, is provided
  849. but not enabled by default. For example, the UNIX "ps" command can be
  850. given the command line "option"
  851.  
  852.   -vax
  853.  
  854. which means the combination of B<-v>, B<-a> and B<-x>. With the new
  855. syntax B<--vax> would be a single option, probably indicating a
  856. computer architecture. 
  857.  
  858. Command line options can be used to set values. These values can be
  859. specified in one of two ways:
  860.  
  861.   --size 24
  862.   --size=24
  863.  
  864. GetOptions is called with a list of option-descriptions, each of which
  865. consists of two elements: the option specifier and the option linkage.
  866. The option specifier defines the name of the option and, optionally,
  867. the value it can take. The option linkage is usually a reference to a
  868. variable that will be set when the option is used. For example, the
  869. following call to GetOptions:
  870.  
  871.   GetOptions("size=i" => \$offset);
  872.  
  873. will accept a command line option "size" that must have an integer
  874. value. With a command line of "--size 24" this will cause the variable
  875. $offset to get the value 24.
  876.  
  877. Alternatively, the first argument to GetOptions may be a reference to
  878. a HASH describing the linkage for the options, or an object whose
  879. class is based on a HASH. The following call is equivalent to the
  880. example above:
  881.  
  882.   %optctl = ("size" => \$offset);
  883.   GetOptions(\%optctl, "size=i");
  884.  
  885. Linkage may be specified using either of the above methods, or both.
  886. Linkage specified in the argument list takes precedence over the
  887. linkage specified in the HASH.
  888.  
  889. The command line options are taken from array @ARGV. Upon completion
  890. of GetOptions, @ARGV will contain the rest (i.e. the non-options) of
  891. the command line.
  892.  
  893. Each option specifier designates the name of the option, optionally
  894. followed by an argument specifier.
  895.  
  896. Options that do not take arguments will have no argument specifier. 
  897. The option variable will be set to 1 if the option is used.
  898.  
  899. For the other options, the values for argument specifiers are:
  900.  
  901. =over 8
  902.  
  903. =item !
  904.  
  905. Option does not take an argument and may be negated, i.e. prefixed by
  906. "no". E.g. "foo!" will allow B<--foo> (with value 1) and B<-nofoo>
  907. (with value 0).
  908. The option variable will be set to 1, or 0 if negated.
  909.  
  910. =item +
  911.  
  912. Option does not take an argument and will be incremented by 1 every
  913. time it appears on the command line. E.g. "more+", when used with
  914. B<--more --more --more>, will set the option variable to 3 (provided
  915. it was 0 or undefined at first).
  916.  
  917. The B<+> specifier is ignored if the option destination is not a SCALAR.
  918.  
  919. =item =s
  920.  
  921. Option takes a mandatory string argument.
  922. This string will be assigned to the option variable.
  923. Note that even if the string argument starts with B<-> or B<-->, it
  924. will not be considered an option on itself.
  925.  
  926. =item :s
  927.  
  928. Option takes an optional string argument.
  929. This string will be assigned to the option variable.
  930. If omitted, it will be assigned "" (an empty string).
  931. If the string argument starts with B<-> or B<-->, it
  932. will be considered an option on itself.
  933.  
  934. =item =i
  935.  
  936. Option takes a mandatory integer argument.
  937. This value will be assigned to the option variable.
  938. Note that the value may start with B<-> to indicate a negative
  939. value. 
  940.  
  941. =item :i
  942.  
  943. Option takes an optional integer argument.
  944. This value will be assigned to the option variable.
  945. If omitted, the value 0 will be assigned.
  946. Note that the value may start with B<-> to indicate a negative
  947. value.
  948.  
  949. =item =f
  950.  
  951. Option takes a mandatory real number argument.
  952. This value will be assigned to the option variable.
  953. Note that the value may start with B<-> to indicate a negative
  954. value.
  955.  
  956. =item :f
  957.  
  958. Option takes an optional real number argument.
  959. This value will be assigned to the option variable.
  960. If omitted, the value 0 will be assigned.
  961.  
  962. =back
  963.  
  964. A lone dash B<-> is considered an option, the corresponding option
  965. name is the empty string.
  966.  
  967. A double dash on itself B<--> signals end of the options list.
  968.  
  969. =head2 Linkage specification
  970.  
  971. The linkage specifier is optional. If no linkage is explicitly
  972. specified but a ref HASH is passed, GetOptions will place the value in
  973. the HASH. For example:
  974.  
  975.   %optctl = ();
  976.   GetOptions (\%optctl, "size=i");
  977.  
  978. will perform the equivalent of the assignment
  979.  
  980.   $optctl{"size"} = 24;
  981.  
  982. For array options, a reference to an array is used, e.g.:
  983.  
  984.   %optctl = ();
  985.   GetOptions (\%optctl, "sizes=i@");
  986.  
  987. with command line "-sizes 24 -sizes 48" will perform the equivalent of
  988. the assignment
  989.  
  990.   $optctl{"sizes"} = [24, 48];
  991.  
  992. For hash options (an option whose argument looks like "name=value"),
  993. a reference to a hash is used, e.g.:
  994.  
  995.   %optctl = ();
  996.   GetOptions (\%optctl, "define=s%");
  997.  
  998. with command line "--define foo=hello --define bar=world" will perform the
  999. equivalent of the assignment
  1000.  
  1001.   $optctl{"define"} = {foo=>'hello', bar=>'world')
  1002.  
  1003. If no linkage is explicitly specified and no ref HASH is passed,
  1004. GetOptions will put the value in a global variable named after the
  1005. option, prefixed by "opt_". To yield a usable Perl variable,
  1006. characters that are not part of the syntax for variables are
  1007. translated to underscores. For example, "--fpp-struct-return" will set
  1008. the variable $opt_fpp_struct_return. Note that this variable resides
  1009. in the namespace of the calling program, not necessarily B<main>.
  1010. For example:
  1011.  
  1012.   GetOptions ("size=i", "sizes=i@");
  1013.  
  1014. with command line "-size 10 -sizes 24 -sizes 48" will perform the
  1015. equivalent of the assignments
  1016.  
  1017.   $opt_size = 10;
  1018.   @opt_sizes = (24, 48);
  1019.  
  1020. A lone dash B<-> is considered an option, the corresponding Perl
  1021. identifier is $opt_ .
  1022.  
  1023. The linkage specifier can be a reference to a scalar, a reference to
  1024. an array, a reference to a hash or a reference to a subroutine.
  1025.  
  1026. Note that, if your code is running under the recommended C<use strict
  1027. 'vars'> pragma, it may be helpful to declare these package variables
  1028. via C<use vars> perhaps something like this:
  1029.  
  1030.   use vars qw/ $opt_size @opt_sizes $opt_bar /;
  1031.  
  1032. If a REF SCALAR is supplied, the new value is stored in the referenced
  1033. variable. If the option occurs more than once, the previous value is
  1034. overwritten. 
  1035.  
  1036. If a REF ARRAY is supplied, the new value is appended (pushed) to the
  1037. referenced array. 
  1038.  
  1039. If a REF HASH is supplied, the option value should look like "key" or
  1040. "key=value" (if the "=value" is omitted then a value of 1 is implied).
  1041. In this case, the element of the referenced hash with the key "key"
  1042. is assigned "value". 
  1043.  
  1044. If a REF CODE is supplied, the referenced subroutine is called with
  1045. two arguments: the option name and the option value.
  1046. The option name is always the true name, not an abbreviation or alias.
  1047.  
  1048. =head2 Aliases and abbreviations
  1049.  
  1050. The option name may actually be a list of option names, separated by
  1051. "|"s, e.g. "foo|bar|blech=s". In this example, "foo" is the true name
  1052. of this option. If no linkage is specified, options "foo", "bar" and
  1053. "blech" all will set $opt_foo. For convenience, the single character
  1054. "?" is allowed as an alias, e.g. "help|?".
  1055.  
  1056. Option names may be abbreviated to uniqueness, depending on
  1057. configuration option B<auto_abbrev>.
  1058.  
  1059. =head2 Non-option call-back routine
  1060.  
  1061. A special option specifier, E<lt>E<gt>, can be used to designate a subroutine
  1062. to handle non-option arguments. GetOptions will immediately call this
  1063. subroutine for every non-option it encounters in the options list.
  1064. This subroutine gets the name of the non-option passed.
  1065. This feature requires configuration option B<permute>, see section
  1066. CONFIGURATION OPTIONS.
  1067.  
  1068. See also the examples.
  1069.  
  1070. =head2 Option starters
  1071.  
  1072. On the command line, options can start with B<-> (traditional), B<-->
  1073. (POSIX) and B<+> (GNU, now being phased out). The latter is not
  1074. allowed if the environment variable B<POSIXLY_CORRECT> has been
  1075. defined.
  1076.  
  1077. Options that start with "--" may have an argument appended, separated
  1078. with an "=", e.g. "--foo=bar".
  1079.  
  1080. =head2 Return values and Errors
  1081.  
  1082. Configuration errors and errors in the option definitions are
  1083. signalled using C<die()> and will terminate the calling
  1084. program unless the call to C<Getopt::Long::GetOptions()> was embedded
  1085. in C<eval { ... }> or C<die()> was trapped using C<$SIG{__DIE__}>.
  1086.  
  1087. A return value of 1 (true) indicates success.
  1088.  
  1089. A return status of 0 (false) indicates that the function detected one
  1090. or more errors during option parsing. These errors are signalled using
  1091. C<warn()> and can be trapped with C<$SIG{__WARN__}>.
  1092.  
  1093. Errors that can't happen are signalled using C<Carp::croak()>.
  1094.  
  1095. =head1 COMPATIBILITY
  1096.  
  1097. Getopt::Long::GetOptions() is the successor of
  1098. B<newgetopt.pl> that came with Perl 4. It is fully upward compatible.
  1099. In fact, the Perl 5 version of newgetopt.pl is just a wrapper around
  1100. the module.
  1101.  
  1102. If an "@" sign is appended to the argument specifier, the option is
  1103. treated as an array. Value(s) are not set, but pushed into array
  1104. @opt_name. If explicit linkage is supplied, this must be a reference
  1105. to an ARRAY.
  1106.  
  1107. If an "%" sign is appended to the argument specifier, the option is
  1108. treated as a hash. Value(s) of the form "name=value" are set by
  1109. setting the element of the hash %opt_name with key "name" to "value"
  1110. (if the "=value" portion is omitted it defaults to 1). If explicit
  1111. linkage is supplied, this must be a reference to a HASH.
  1112.  
  1113. If configuration option B<getopt_compat> is set (see section
  1114. CONFIGURATION OPTIONS), options that start with "+" or "-" may also
  1115. include their arguments, e.g. "+foo=bar". This is for compatiblity
  1116. with older implementations of the GNU "getopt" routine.
  1117.  
  1118. If the first argument to GetOptions is a string consisting of only
  1119. non-alphanumeric characters, it is taken to specify the option starter
  1120. characters. Everything starting with one of these characters from the
  1121. starter will be considered an option. B<Using a starter argument is
  1122. strongly deprecated.>
  1123.  
  1124. For convenience, option specifiers may have a leading B<-> or B<-->,
  1125. so it is possible to write:
  1126.  
  1127.    GetOptions qw(-foo=s --bar=i --ar=s);
  1128.  
  1129. =head1 EXAMPLES
  1130.  
  1131. If the option specifier is "one:i" (i.e. takes an optional integer
  1132. argument), then the following situations are handled:
  1133.  
  1134.    -one -two        -> $opt_one = '', -two is next option
  1135.    -one -2        -> $opt_one = -2
  1136.  
  1137. Also, assume specifiers "foo=s" and "bar:s" :
  1138.  
  1139.    -bar -xxx        -> $opt_bar = '', '-xxx' is next option
  1140.    -foo -bar        -> $opt_foo = '-bar'
  1141.    -foo --        -> $opt_foo = '--'
  1142.  
  1143. In GNU or POSIX format, option names and values can be combined:
  1144.  
  1145.    +foo=blech        -> $opt_foo = 'blech'
  1146.    --bar=        -> $opt_bar = ''
  1147.    --bar=--        -> $opt_bar = '--'
  1148.  
  1149. Example of using variable references:
  1150.  
  1151.    $ret = GetOptions ('foo=s', \$foo, 'bar=i', 'ar=s', \@ar);
  1152.  
  1153. With command line options "-foo blech -bar 24 -ar xx -ar yy" 
  1154. this will result in:
  1155.  
  1156.    $foo = 'blech'
  1157.    $opt_bar = 24
  1158.    @ar = ('xx','yy')
  1159.  
  1160. Example of using the E<lt>E<gt> option specifier:
  1161.  
  1162.    @ARGV = qw(-foo 1 bar -foo 2 blech);
  1163.    GetOptions("foo=i", \$myfoo, "<>", \&mysub);
  1164.  
  1165. Results:
  1166.  
  1167.    mysub("bar") will be called (with $myfoo being 1)
  1168.    mysub("blech") will be called (with $myfoo being 2)
  1169.  
  1170. Compare this with:
  1171.  
  1172.    @ARGV = qw(-foo 1 bar -foo 2 blech);
  1173.    GetOptions("foo=i", \$myfoo);
  1174.  
  1175. This will leave the non-options in @ARGV:
  1176.  
  1177.    $myfoo -> 2
  1178.    @ARGV -> qw(bar blech)
  1179.  
  1180. =head1 CONFIGURATION OPTIONS
  1181.  
  1182. B<GetOptions> can be configured by calling subroutine
  1183. B<Getopt::Long::Configure>. This subroutine takes a list of quoted
  1184. strings, each specifying a configuration option to be set, e.g.
  1185. B<ignore_case>. Options can be reset by prefixing with B<no_>, e.g.
  1186. B<no_ignore_case>. Case does not matter. Multiple calls to B<config>
  1187. are possible.
  1188.  
  1189. Previous versions of Getopt::Long used variables for the purpose of
  1190. configuring. Although manipulating these variables still work, it
  1191. is strongly encouraged to use the new B<config> routine. Besides, it
  1192. is much easier.
  1193.  
  1194. The following options are available:
  1195.  
  1196. =over 12
  1197.  
  1198. =item default
  1199.  
  1200. This option causes all configuration options to be reset to their
  1201. default values.
  1202.  
  1203. =item auto_abbrev
  1204.  
  1205. Allow option names to be abbreviated to uniqueness.
  1206. Default is set unless environment variable
  1207. POSIXLY_CORRECT has been set, in which case B<auto_abbrev> is reset.
  1208.  
  1209. =item getopt_compat   
  1210.  
  1211. Allow '+' to start options.
  1212. Default is set unless environment variable
  1213. POSIXLY_CORRECT has been set, in which case B<getopt_compat> is reset.
  1214.  
  1215. =item require_order
  1216.  
  1217. Whether non-options are allowed to be mixed with
  1218. options.
  1219. Default is set unless environment variable
  1220. POSIXLY_CORRECT has been set, in which case b<require_order> is reset.
  1221.  
  1222. See also B<permute>, which is the opposite of B<require_order>.
  1223.  
  1224. =item permute
  1225.  
  1226. Whether non-options are allowed to be mixed with
  1227. options.
  1228. Default is set unless environment variable
  1229. POSIXLY_CORRECT has been set, in which case B<permute> is reset.
  1230. Note that B<permute> is the opposite of B<require_order>.
  1231.  
  1232. If B<permute> is set, this means that 
  1233.  
  1234.     -foo arg1 -bar arg2 arg3
  1235.  
  1236. is equivalent to
  1237.  
  1238.     -foo -bar arg1 arg2 arg3
  1239.  
  1240. If a non-option call-back routine is specified, @ARGV will always be
  1241. empty upon succesful return of GetOptions since all options have been
  1242. processed, except when B<--> is used:
  1243.  
  1244.     -foo arg1 -bar arg2 -- arg3
  1245.  
  1246. will call the call-back routine for arg1 and arg2, and terminate
  1247. leaving arg2 in @ARGV.
  1248.  
  1249. If B<require_order> is set, options processing
  1250. terminates when the first non-option is encountered.
  1251.  
  1252.     -foo arg1 -bar arg2 arg3
  1253.  
  1254. is equivalent to
  1255.  
  1256.     -foo -- arg1 -bar arg2 arg3
  1257.  
  1258. =item bundling (default: reset)
  1259.  
  1260. Setting this variable to a non-zero value will allow single-character
  1261. options to be bundled. To distinguish bundles from long option names,
  1262. long options must be introduced with B<--> and single-character
  1263. options (and bundles) with B<->. For example,
  1264.  
  1265.     ps -vax --vax
  1266.  
  1267. would be equivalent to
  1268.  
  1269.     ps -v -a -x --vax
  1270.  
  1271. provided "vax", "v", "a" and "x" have been defined to be valid
  1272. options. 
  1273.  
  1274. Bundled options can also include a value in the bundle; for strings
  1275. this value is the rest of the bundle, but integer and floating values
  1276. may be combined in the bundle, e.g.
  1277.  
  1278.     scale -h24w80
  1279.  
  1280. is equivalent to
  1281.  
  1282.     scale -h 24 -w 80
  1283.  
  1284. Note: resetting B<bundling> also resets B<bundling_override>.
  1285.  
  1286. =item bundling_override (default: reset)
  1287.  
  1288. If B<bundling_override> is set, bundling is enabled as with
  1289. B<bundling> but now long option names override option bundles. In the
  1290. above example, B<-vax> would be interpreted as the option "vax", not
  1291. the bundle "v", "a", "x".
  1292.  
  1293. Note: resetting B<bundling_override> also resets B<bundling>.
  1294.  
  1295. B<Note:> Using option bundling can easily lead to unexpected results,
  1296. especially when mixing long options and bundles. Caveat emptor.
  1297.  
  1298. =item ignore_case  (default: set)
  1299.  
  1300. If set, case is ignored when matching options.
  1301.  
  1302. Note: resetting B<ignore_case> also resets B<ignore_case_always>.
  1303.  
  1304. =item ignore_case_always (default: reset)
  1305.  
  1306. When bundling is in effect, case is ignored on single-character
  1307. options also. 
  1308.  
  1309. Note: resetting B<ignore_case_always> also resets B<ignore_case>.
  1310.  
  1311. =item pass_through (default: reset)
  1312.  
  1313. Unknown options are passed through in @ARGV instead of being flagged
  1314. as errors. This makes it possible to write wrapper scripts that
  1315. process only part of the user supplied options, and passes the
  1316. remaining options to some other program.
  1317.  
  1318. This can be very confusing, especially when B<permute> is also set.
  1319.  
  1320. =item prefix
  1321.  
  1322. The string that starts options. See also B<prefix_pattern>.
  1323.  
  1324. =item prefix_pattern
  1325.  
  1326. A Perl pattern that identifies the strings that introduce options.
  1327. Default is C<(--|-|\+)> unless environment variable
  1328. POSIXLY_CORRECT has been set, in which case it is C<(--|-)>.
  1329.  
  1330. =item debug (default: reset)
  1331.  
  1332. Enable copious debugging output.
  1333.  
  1334. =back
  1335.  
  1336. =head1 OTHER USEFUL VARIABLES
  1337.  
  1338. =over 12
  1339.  
  1340. =item $Getopt::Long::VERSION
  1341.  
  1342. The version number of this Getopt::Long implementation in the format
  1343. C<major>.C<minor>. This can be used to have Exporter check the
  1344. version, e.g.
  1345.  
  1346.     use Getopt::Long 3.00;
  1347.  
  1348. You can inspect $Getopt::Long::major_version and
  1349. $Getopt::Long::minor_version for the individual components.
  1350.  
  1351. =item $Getopt::Long::error
  1352.  
  1353. Internal error flag. May be incremented from a call-back routine to
  1354. cause options parsing to fail.
  1355.  
  1356. =back
  1357.  
  1358. =head1 AUTHOR
  1359.  
  1360. Johan Vromans E<lt>jvromans@squirrel.nlE<gt>
  1361.  
  1362. =head1 COPYRIGHT AND DISCLAIMER
  1363.  
  1364. This program is Copyright 1990,1998 by Johan Vromans.
  1365. This program is free software; you can redistribute it and/or
  1366. modify it under the terms of the GNU General Public License
  1367. as published by the Free Software Foundation; either version 2
  1368. of the License, or (at your option) any later version.
  1369.  
  1370. This program is distributed in the hope that it will be useful,
  1371. but WITHOUT ANY WARRANTY; without even the implied warranty of
  1372. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  1373. GNU General Public License for more details.
  1374.  
  1375. If you do not have a copy of the GNU General Public License write to
  1376. the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, 
  1377. MA 02139, USA.
  1378.  
  1379. =cut
  1380.